package com.turnengine.client.global.game.command;

import com.javabi.command.IExecutableCommand;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.serializer.AbstractCommandDataSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import com.turnengine.client.global.game.bean.GameHostSerializer;
import com.turnengine.client.global.game.bean.IGameHost;
import java.io.IOException;

/**
 * The Get Game Host By Id Data Serializer.
 */
public class GetGameHostByIdDataSerializer extends AbstractCommandDataSerializer<IGameHost> implements IGetGameHostByIdDataSerializer {

	/**
	 * Creates a new Get Game Host By Id Data Serializer.
	 */
	public GetGameHostByIdDataSerializer() {
		super(GetGameHostById.COMMAND_ID);
	}

	@Override
	public IGameHost readReturnValue(IDataReader reader) throws IOException {
		IGameHost value = new GameHostSerializer().readObject(reader);
		return value;
	}

	@Override
	public void writeReturnValue(IDataWriter writer, IGameHost value) throws IOException {
		new GameHostSerializer().writeObject(writer, value);
	}

	@Override
	public IExecutableCommand<IGameHost> readRequest(IDataReader reader) throws IOException {

		// Read fields
		int id = reader.readInt();

		// Create object
		GetGameHostById object = new GetGameHostById();
		object.setId(id);
		return object;
	}

	@Override
	public void writeRequest(IDataWriter writer, IExecutableCommand<IGameHost> argument) throws IOException {
		GetGameHostById object = (GetGameHostById) argument;

		// Get fields
		int id = object.getId();

		// Write fields
		writer.writeInt(id);
	}

	@Override
	public IExecutableCommandResponse<IGameHost> newResponse() {
		return new GetGameHostByIdResponse();
	}
}
